package com.zhongjian.technologycal.mall.adapter;

import android.content.Context;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.BaseAdapter;
import android.widget.TextView;

import com.zhongjian.technologycal.mall.R;
import com.zhongjian.technologycal.mall.bean.PresenterNoBean;
import com.zhongjian.technologycal.mall.bean.PresenterOverBean;

import java.util.List;

/**
 * Created by wei on 2018/1/29.
 */

public class PresenterOverAdapter extends BaseAdapter {

    private Context context;
    private List<PresenterOverBean> listItems;
    private LayoutInflater listContainer;

    public final class ViewHolder {
        public TextView mall_tv_userid;
        public TextView mall_tv_level;
        public TextView mall_tv_presenter_commit;

    }

    public PresenterOverAdapter(Context context, List<PresenterOverBean> listItems) {
        this.context = context;
        listContainer = LayoutInflater.from(context);
        this.listItems = listItems;
    }

    @Override
    public int getCount() {
        return listItems.size();
    }

    @Override
    public Object getItem(int position) {
        return listItems.get(position);
    }

    @Override
    public long getItemId(int position) {
        return position;
    }

    @Override
    public View getView(final int position, View convertView, ViewGroup parent) {
        PresenterOverAdapter.ViewHolder viewHolder = null;
        if (convertView == null) {
            viewHolder = new PresenterOverAdapter.ViewHolder();
            convertView = listContainer.inflate(R.layout.items_over_presenter,
                    null);
            viewHolder.mall_tv_userid = (TextView) convertView
                    .findViewById(R.id.over_mall_tv_userid);
            viewHolder.mall_tv_level = (TextView) convertView
                    .findViewById(R.id.over_mall_tv_level);
            viewHolder.mall_tv_presenter_commit = (TextView) convertView
                    .findViewById(R.id.over_mall_tv_presenter_commit);

            convertView.setTag(viewHolder);
        } else {
            viewHolder = (PresenterOverAdapter.ViewHolder) convertView.getTag();
        }

        //将数据填充到具体的view中
        viewHolder.mall_tv_userid.setText("被赠送人:"+listItems.get(position).getData().get(position).getSysID());

        if(listItems.get(position).getData().get(position).getLev() == 0){
            viewHolder.mall_tv_level.setText("等级: 免费");
        }else if(listItems.get(position).getData().get(position).getLev() == 1){
            viewHolder.mall_tv_level.setText("等级: VIP");
        }else if(listItems.get(position).getData().get(position).getLev() == 2){
            viewHolder.mall_tv_level.setText("等级: 合伙人");

        }else if(listItems.get(position).getData().get(position).getLev() == 3){
            viewHolder.mall_tv_level.setText("等级: 准代理");

        }else if(listItems.get(position).getData().get(position).getLev() == 4){
            viewHolder.mall_tv_level.setText("等级: 代理");

        }

        return convertView;
    }
}
